package com.ktjy.crm;

import com.ktjy.crm.entity.Role;
import com.ktjy.crm.mapper.RoleMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class RoleMapperTester {
    @Autowired
    private RoleMapper roleMapper;

    // 测试查询
    @Test
    public void testSelect() throws Exception {
        List<Role> roleList = roleMapper.findAll();
        for (Role role : roleList){
            System.out.println(role.getRoleId()+" "+role.getRoleName()+" "
                    +role.getRoleName()+" "+role.getRoleName()+" "+role.getRoleFlag());
        }
    }

    // 测试新增
    @Test
    public void testInsert() throws Exception {
        int role = roleMapper.insert(new Role(null,"老板", "CEO",1));
        if (role > 0){
            System.out.println("插入成功");
        }else {
            System.out.println("插入失败");
        }
    }

    // 测试删除
    @Test
    public void testDelete() throws Exception {
        int role = roleMapper.delete(4);
        if (role > 0){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }

    // 测试修改
    @Test
    public void testUpdate() throws Exception {
        int role = roleMapper.update(new Role(5,"员工", "员工",1));
        if (role > 0){
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
    }

}
